using MediatR;
using Microsoft.EntityFrameworkCore;
using NLog.Web;
using SheepCultivation.Common.EFDb;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Common.Infrastructure.Repository;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddDbContext<EFDBContext>(x => x.UseSqlServer(builder.Configuration.GetConnectionString("DB")));

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
    var path = AppDomain.CurrentDomain.BaseDirectory + "SheepCultivation.API.xml";
    x.IncludeXmlComments(path, true);
});
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepsoitory<>));
builder.Services.AddMediatR(Assembly.GetExecutingAssembly());
builder.Host.UseNLog();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
app.UseStaticFiles();

app.UseAuthorization();

app.MapControllers();

app.Run();
